package com.eningqu.aipen.ui.adapter;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.eningqu.aipen.demo.R;
import com.eningqu.aipen.demo.databinding.GvFilterImageBinding;
import com.eningqu.aipen.ui.medical.PreviewPicActivity;

import java.util.ArrayList;

/**
 * Package:com.eningqu.aipen.ui.adapter
 * Author:starr
 * Time:11/23/2023 1:45 PM
 * Description: 九宫格图片适配器
 */
public class GridNineAdapter extends RecyclerView.Adapter<GridNineAdapter.NineViewHolder> {


    ArrayList<String> list;
    public GridNineAdapter(ArrayList<String> list) {
        this.list = list;
    }

    @NonNull
    @Override
    public NineViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        GvFilterImageBinding binding = DataBindingUtil.inflate(LayoutInflater.from(viewGroup.getContext()), R.layout.gv_filter_image, viewGroup, false);
        NineViewHolder viewHolder = new NineViewHolder(binding.getRoot());
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull NineViewHolder holder, int i) {
        GvFilterImageBinding binding = DataBindingUtil.getBinding(holder.itemView);
        Glide.with(holder.itemView)
                .load(list.get(i))
                .centerCrop()
                .placeholder(R.drawable.pic_empty)
                .into(binding.fiv);
        binding.fiv.setOnClickListener(view -> {
            Bundle bundle=new Bundle();
            bundle.putStringArrayList("img",list);
            bundle.putInt("pos",i);
            PreviewPicActivity.startAction(binding.getRoot().getContext(), bundle);
        });
    }

    @Override
    public int getItemCount() {
        return list.size();
    }



    protected class NineViewHolder extends RecyclerView.ViewHolder {

        public NineViewHolder(@NonNull View itemView) {
            super(itemView);
        }
    }
}
